#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Created: Tue May 18 19:12:46 2010

from sys import argv
from PyQt4 import QtCore, QtGui

class FrameLogsManager(QtGui.QFrame):
    def __init__(self, connection, parent = None):
        super(FrameLogsManager, self).__init__(parent)
        """setup Interface"""
        self.setupUi(self)
        
        self.connection = connection
        self.LogsManager = self.connection.root.Modules.LogFilter.LogFilter()
        
    def setupUi(self, logs_manager_frame):
        logs_manager_frame.setObjectName("logs_manager_frame")
        logs_manager_frame.resize(819, 580)
        logs_manager_frame.setGeometry(QtCore.QRect(210, 45, 831, 581))
        logs_manager_frame.setFrameShape(QtGui.QFrame.StyledPanel)
        logs_manager_frame.setFrameShadow(QtGui.QFrame.Raised)
        self.gridLayout_2 = QtGui.QGridLayout(logs_manager_frame)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.groupBox = QtGui.QGroupBox(logs_manager_frame)
        self.groupBox.setObjectName("groupBox")
        self.gridLayout = QtGui.QGridLayout(self.groupBox)
        self.gridLayout.setObjectName("gridLayout")
        self.label = QtGui.QLabel(self.groupBox)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
        self.combo_logTypes = QtGui.QComboBox(self.groupBox)
        self.combo_logTypes.setObjectName("combo_logTypes")
        self.combo_logTypes.addItem("")
        self.combo_logTypes.addItem("")
        self.combo_logTypes.addItem("")
        self.combo_logTypes.addItem("")
        self.combo_logTypes.addItem("")
        self.combo_logTypes.addItem("")
        self.combo_logTypes.addItem("")
        self.gridLayout.addWidget(self.combo_logTypes, 0, 1, 1, 1)
        spacerItem = QtGui.QSpacerItem(300, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.gridLayout.addItem(spacerItem, 0, 2, 1, 1)
        self.btn_getLog = QtGui.QPushButton(self.groupBox)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("icons/accessories-text-editor.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.btn_getLog.setIcon(icon)
        self.btn_getLog.setObjectName("btn_getLog")
        self.gridLayout.addWidget(self.btn_getLog, 0, 3, 1, 1)
        self.gridLayout_2.addWidget(self.groupBox, 0, 0, 1, 1)
        self.textEdit = QtGui.QTextEdit(logs_manager_frame)
        self.textEdit.setObjectName("textEdit")
        self.gridLayout_2.addWidget(self.textEdit, 1, 0, 1, 1)

        self.retranslateUi(logs_manager_frame)
        self.connect(self.btn_getLog, QtCore.SIGNAL('clicked()'), self.getLog)
        QtCore.QMetaObject.connectSlotsByName(logs_manager_frame)

    def retranslateUi(self, logs_manager_frame):
        logs_manager_frame.setWindowTitle(QtGui.QApplication.translate("logs_manager_frame", "Frame", None, QtGui.QApplication.UnicodeUTF8))
        self.groupBox.setTitle(QtGui.QApplication.translate("logs_manager_frame", "Get Logs", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("logs_manager_frame", "Choose log type", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_logTypes.setItemText(0, QtGui.QApplication.translate("logs_manager_frame", "Choose log type......", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_logTypes.setItemText(1, QtGui.QApplication.translate("logs_manager_frame", "General log for all applications", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_logTypes.setItemText(2, QtGui.QApplication.translate("logs_manager_frame", "Cron jobs log", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_logTypes.setItemText(3, QtGui.QApplication.translate("logs_manager_frame", "Mail log", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_logTypes.setItemText(4, QtGui.QApplication.translate("logs_manager_frame", "Private authentication log", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_logTypes.setItemText(5, QtGui.QApplication.translate("logs_manager_frame", "Boot log", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_logTypes.setItemText(6, QtGui.QApplication.translate("logs_manager_frame", "Yum log", None, QtGui.QApplication.UnicodeUTF8))
        self.btn_getLog.setText(QtGui.QApplication.translate("logs_manager_frame", "Get Log....", None, QtGui.QApplication.UnicodeUTF8))

    
    def getLog(self):
        logType = str(self.combo_logTypes.currentText())
        if logType == "General log for all applications":
            self.textEdit.setText(self.LogsManager.messageLog())
        elif logType == "Cron jobs log":
            self.textEdit.setText(self.LogsManager.cronLogFiltering())
        elif logType == "Mail log":
            self.textEdit.setText(self.LogsManager.mailLog())
        elif logType == "Private authentication log":
            self.textEdit.setText(self.LogsManager.privateAuth())
        elif logType == "Boot log":
            self.textEdit.setText(self.LogsManager.bootLog())
        elif logType == "Yum log": 
            self.textEdit.setText(self.LogsManager.yumLog())
        else:
            QtGui.QMessageBox.warning(self, "Warning","Please select log type")
    
if __name__ == '__main__':
    app = QtGui.QApplication(argv)
    abstract_window = FrameLogsManager()
    abstract_window.show()
    app.exec_()
